//
//  HomeViewController.m
//  FengyuanXS
//
//  Created by 王冬 on 2020/7/25.
//  Copyright © 2020 王冬. All rights reserved.
//

#import "HomeViewController.h"
#import "HomeViewCell.h"
#import "HomeCollectionViewCell.h"
#import "HelpViewController.h"
#import "DZViewController.h"
#import "StudyViewController.h"
#import "RegulationViewController.h"
#import "THotlineViewController.h"
#import "DevelopmentViewController.h"
#import "ComplaintController.h"
#import "BaseWebViewController.h"
#import "AppealDetailController.h"
#import "EmployeeAppeaController.h"
#import "SqFenFaViewController.h"
#import "SqHomeBanliController.h"
#import "SectionNormalViewController.h"
#import "SqDetailListViewController.h"
#import "HomeDetailFinshtViewController.h"
#import "HomeFinshtViewController.h"
#import "TongXunViewController.h"
static const CGFloat kLineSpacing = 1.f;   //列间距 |
static const CGFloat kItemSpacing = 1.f;   //item之间的间距  --
static const NSInteger kRowNumber = 4;     //列数

@interface HomeViewController ()<UITableViewDelegate,UITableViewDataSource,SDCycleScrollViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet SDCycleScrollView *sdcycleScrollView;
@property (nonatomic, strong) NSMutableArray *bannerArray;

@property (nonatomic, strong) NSMutableArray *handleArray;// 处理中
@property (nonatomic, strong) NSMutableArray *finishArray;// 已完成
@property (nonatomic, strong) NSMutableArray *backArray;// 已退回
@property (weak, nonatomic) IBOutlet UILabel *leftLabel;
@property (weak, nonatomic) IBOutlet UILabel *centerLabel;
@property (weak, nonatomic) IBOutlet UILabel *rightLabel;
@property (weak, nonatomic) IBOutlet BoardView *backView;
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

@property (nonatomic, strong) NSArray *imageArray;
@property (nonatomic, strong) NSArray *titleArray;
@property (nonatomic, strong) NSMutableArray *imageMuArray;
@property (nonatomic, strong) NSMutableArray *titleMuArray;
@property (weak, nonatomic) IBOutlet BoardLabel *leftNumLabel;
@property (weak, nonatomic) IBOutlet BoardLabel *centerNumLabel;
@property (weak, nonatomic) IBOutlet BoardLabel *rightNumLabel;

@property (nonatomic ,assign) int page;
@property (nonatomic ,copy) NSString *status;
@property (nonatomic, copy) NSString *num;
@property (nonatomic, copy) NSString *num1;
@property (nonatomic, copy) NSString *num2;

@property (nonatomic, strong) NSMutableDictionary *cellDic;
@end

@implementation HomeViewController

-(NSMutableArray *)imageMuArray{
    if (!_imageMuArray) {
        _imageMuArray = [NSMutableArray array];
    }
    return _imageMuArray;
    
}

-(NSMutableArray *)titleMuArray{
    if (!_titleMuArray) {
        _titleMuArray = [NSMutableArray array];
    }
    return _titleMuArray;
    
}

- (NSMutableArray *)bannerArray{
    if (!_bannerArray) {
        _bannerArray = [NSMutableArray array];
    }
    return _bannerArray;
}
-(NSMutableArray *)handleArray{
    if (!_handleArray) {
        _handleArray = [NSMutableArray array];
    }
    return _handleArray;
}
-(NSMutableArray *)finishArray{
    
    if (!_finishArray) {
        _finishArray = [NSMutableArray array];
    }
    return _finishArray;
}
-(NSMutableArray *)backArray{
    if (!_backArray) {
        _backArray = [NSMutableArray array];
    }
    return _backArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.leftLabel.hidden = NO;
    self.centerLabel.hidden = YES;
    self.rightLabel.hidden = YES;
    
    
    
    
    self.sdcycleScrollView.delegate = self;
    self.sdcycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleNone;
    self.sdcycleScrollView.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.sdcycleScrollView.pageControlAliment =SDCycleScrollViewPageContolAlimentRight;
    self.sdcycleScrollView.placeholderImage = [UIImage imageNamed:@"banner"];
    self.sdcycleScrollView.backgroundColor = [UIColor whiteColor];
    
    self.tableView.rowHeight = 100;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.emptyDataSetSource = self;
    self.tableView.emptyDataSetDelegate = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:@"HomeViewCell" bundle:nil] forCellReuseIdentifier:@"HomeViewCell"];
    
    
    
    
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        [self getListStatus:self.status];
    }];
    
    self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        [self getListStatus:self.status];
    }];
    [self getData];
    self.status = @"0";
    
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self getPhone];
    self.navigationController.navigationBar.hidden = YES;
    [self.handleArray removeAllObjects];
    [self.imageMuArray removeAllObjects];
    [self.titleMuArray removeAllObjects];
    
    self.cellDic = [[NSMutableDictionary alloc] init];
    
    self.titleArray = @[@"职工诉求",@"发展建议",@"投诉检举",@"热线服务",@"帮扶救助",@"政策法规",@"党政之声",@"学习园地",@"丰源通讯",@"集团网站"];
    self.imageArray = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"home_fytx",@"9"];
    
    [self.imageMuArray addObjectsFromArray:self.imageArray];
    [self.titleMuArray addObjectsFromArray:self.titleArray];
    
    if ([[TokenManager getSection_main]isEqualToString:@"0"]&&[[TokenManager getSection_normal]isEqualToString:@"0"]&&[[TokenManager getLeader_main]isEqualToString:@"0"]&&[[TokenManager getLeader_normal]isEqualToString:@"0"]) {
        
    }
    if ([[TokenManager getLeader_normal]isEqualToString:@"1"]) {
        [self.imageMuArray addObject:@"10"];
        [self.titleMuArray addObject:@"诉求列表"];
        
    }
    
    
    if (([[TokenManager getSection_main]isEqualToString:@"1"]||[[TokenManager getSection_main]isEqualToString:@"2"])) {
        [self.imageMuArray addObject:@"11"];
        [self.titleMuArray addObject:@"诉求研判"];
        [self numData:@"3"];
    }
    
    if (([[TokenManager getSection_normal]isEqualToString:@"1"]||[[TokenManager getLeader_main]isEqualToString:@"1"])) {
        
        [self.imageMuArray addObject:@"12"];
        [self.titleMuArray addObject:@"诉求办理"];
        
        if ([[TokenManager getSection_normal]isEqualToString:@"1"]) {
            [self numData1:@"5"];
        }if ([[TokenManager getLeader_main]isEqualToString:@"1"]) {
            [self numData1:@"4"];
        }
        
        
    }
    
    self.page = 1;
    [self getListStatus:self.status];
    
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumLineSpacing    = kLineSpacing;
    layout.minimumInteritemSpacing = kItemSpacing;
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    self.collectionView.collectionViewLayout = layout;
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    //  [self.collectionView  registerNib:[UINib nibWithNibName:@"HomeCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"HomeCollectionViewCell1"];
    
    
    
    
}
-(void)numData:(NSString *)role_id{
    WS(weakSelf);
    [[ApiManager ShardInstance]appealUntreatedNumStaff_id:[TokenManager getUserId] role_id:role_id resultBlock:^(NSDictionary *data, NSError *error) {
        
        NSString *str = [NSString stringWithFormat:@"%@",data[@"rs"]];
        
        
        
        if ([self isPureInt:str]) {
            weakSelf.num = str;
        }else{
            weakSelf.num = @"0";
            
        }
        [weakSelf.collectionView reloadData];
        
    }];
    
    
}

-(void)numData1:(NSString *)role_id{
    WS(weakSelf);
    [[ApiManager ShardInstance]appealUntreatedNumStaff_id:[TokenManager getUserId] role_id:role_id resultBlock:^(NSDictionary *data, NSError *error) {
        
        NSString *str = [NSString stringWithFormat:@"%@",data[@"rs"]];
        
        
        
        if ([self isPureInt:str]) {
            weakSelf.num1 = str;
        }else{
            weakSelf.num1 = @"0";
            
        }
        [weakSelf.collectionView reloadData];
        
    }];
    
    
}

- (BOOL)isPureInt:(NSString*)string{
    NSScanner* scan = [NSScanner scannerWithString:string];
    int val;
    return [scan scanInt:&val] && [scan isAtEnd];
}
-(void)numData2:(NSString *)role_id{
    WS(weakSelf);
    [[ApiManager ShardInstance]appealUntreatedNumStaff_id:[TokenManager getUserId] role_id:role_id resultBlock:^(NSDictionary *data, NSError *error) {
        weakSelf.num2 = [NSString stringWithFormat:@"%@",data[@"rs"]];
        [weakSelf.collectionView reloadData];
        
    }];
    
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return  self.handleArray.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    HomeViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeViewCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    AppealModel *model = self.handleArray[indexPath.row];
    [cell.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:[UIImage imageNamed:@"tou"]];
    cell.bianLabel.text = [NSString stringWithFormat:@"编号:%@",model.appeal_code];
    cell.shenLabel.text = [NSString stringWithFormat:@"申请人:%@",model.real_name];
    cell.buLabel.text = [NSString stringWithFormat:@"部门:%@",model.section_name];
    cell.typeLabel.text = [NSString stringWithFormat:@"类型:%@",model.type_name];
    cell.timeLabel.text = [self ConvertStrToTime:model.create_time];
    
    
    if ([model.status isEqualToString:@"4"]) {
        cell.statusLabel.text = @"已完成";
    }else if ([model.status isEqualToString:@"9"]) {
        cell.statusLabel.text = @"已驳回";
    }else{
        cell.statusLabel.text = @"待处理";
    }
    return cell;
    
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    AppealModel *model = self.handleArray[indexPath.row];
    
    if ([self.status isEqualToString:@"0"]) {
        AppealDetailController *appVC = [AppealDetailController loadStroyboard:[AppealDetailController new]];
        appVC.model = model;
        appVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:appVC animated:YES];
    }
    if ([self.status isEqualToString:@"1"]) {
        
        if ([model.is_appraise isEqualToString:@"0"]) {
            HomeDetailFinshtViewController *sqVC = [HomeDetailFinshtViewController loadStroyboard:[HomeDetailFinshtViewController new]];
            sqVC.appealID = model.id;
            sqVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:sqVC animated:YES];
        }else{
            
            HomeFinshtViewController *sqVC = [HomeFinshtViewController loadStroyboard:[HomeFinshtViewController new]];
            sqVC.appealID = model.id;
            sqVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:sqVC animated:YES];
            
        }//测试一  测试二
        
    }
    if ([self.status isEqualToString:@"2"]) {
        HomeDetailFinshtViewController *sqVC = [HomeDetailFinshtViewController loadStroyboard:[HomeDetailFinshtViewController new]];
        sqVC.appealID = model.id;
        sqVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:sqVC animated:YES];
    }
    
    
}

//时间戳变为格式时间
- (NSString *)ConvertStrToTime:(NSString *)timeStr

{
    
    long long time=[timeStr longLongValue];
    //    如果服务器返回的是13位字符串，需要除以1000，否则显示不正确(13位其实代表的是毫秒，需要除以1000)
    //    long long time=[timeStr longLongValue] / 1000;
    
    NSDate *date = [[NSDate alloc]initWithTimeIntervalSince1970:time];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    
    [formatter setDateFormat:@"yyyy-MM-dd"];
    
    NSString*timeString=[formatter stringFromDate:date];
    
    return timeString;
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.titleMuArray.count;
}

//每个单元格的大小size
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake((collectionView.width-10-kItemSpacing*(kRowNumber-1))/kRowNumber, 80);
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    NSString *identifier = [_cellDic objectForKey:[NSString stringWithFormat:@"%@", indexPath]];
    // 如果取出的唯一标示符不存在，则初始化唯一标示符，并将其存入字典中，对应唯一标示符注册Cell
    if (identifier == nil) {
        identifier = [NSString stringWithFormat:@"%@%@", @"HomeCollectionViewCell1", [NSString stringWithFormat:@"%@", indexPath]];
        [_cellDic setValue:identifier forKey:[NSString stringWithFormat:@"%@", indexPath]];
        // 注册Cell
        [self.collectionView  registerNib:[UINib nibWithNibName:@"HomeCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:identifier];
    }
    
    //  CalendarCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    
    
    HomeCollectionViewCell*cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    cell.iconImageView.image = [UIImage imageNamed:self.imageMuArray[indexPath.row]];
    cell.titleLabel.text = self.titleMuArray[indexPath.row];
    if (indexPath.row ==10) {
        if ([self.titleMuArray[indexPath.row]isEqualToString:@"诉求研判"]) {
            
            if (self.num.intValue > 0) {
                cell.numLabel.hidden = NO;
                cell.numLabel.text = self.num;
            }
            
        }
        if ([self.titleMuArray[indexPath.row] isEqualToString:@"诉求办理"]) {
            
            if (self.num1.intValue > 0){
                cell.numLabel.hidden = NO;
                cell.numLabel.text = self.num1;
            }
            
        }
        
        
    }
    
    if (indexPath.row ==11) {
        
        if ([self.titleMuArray[indexPath.row] isEqualToString:@"诉求办理"]) {
            
            if (self.num1.intValue > 0){
                cell.numLabel.hidden = NO;
                cell.numLabel.text = self.num1;
            }
            
        }
        
        
    }
    
    return cell;
    
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    if (indexPath.row == 0) {
        self.tabBarController.selectedIndex = 1;
    }
    
    if (indexPath.row == 1) {
        DevelopmentViewController *thotlVC = [DevelopmentViewController loadStroyboard:[DevelopmentViewController new]];
        thotlVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:thotlVC animated:YES];
    }
    if (indexPath.row == 2) {
        
        ComplaintController *complanVC = [ComplaintController loadStroyboard:[ComplaintController new]];
        complanVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:complanVC animated:YES];
    }
    
    if (indexPath.row == 3) {
        THotlineViewController *thotlVC = [THotlineViewController loadStroyboard:[THotlineViewController new]];
        thotlVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:thotlVC animated:YES];
    }
    
    if (indexPath.row == 4) {
        
        HelpViewController *helpVC = [HelpViewController loadStroyboard:[HelpViewController new]];
        helpVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:helpVC animated:YES];
        
    }
    if (indexPath.row == 5) {
        RegulationViewController *reguVC = [[RegulationViewController alloc]init];
        reguVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:reguVC animated:YES];
    }
    if (indexPath.row == 6) {
        DZViewController *dzVC = [[DZViewController alloc]init];
        dzVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:dzVC animated:YES];
    }
    if (indexPath.row == 7) {
        StudyViewController *dzVC = [[StudyViewController alloc]init];
        dzVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:dzVC animated:YES];
    }
    if (indexPath.row == 8) {
        TongXunViewController *baseVC = [[TongXunViewController alloc]init];
        baseVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:baseVC animated:YES];
        
        
    }
    if (indexPath.row == 9) {
        BaseWebViewController *baseVC = [[BaseWebViewController alloc]init];
        baseVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:baseVC animated:YES];
        
    }
    
    if (indexPath.row == 10) {
        NSString *titleStr = self.titleMuArray[indexPath.row];
        if ([titleStr isEqualToString:@"诉求列表"]) {
            EmployeeAppeaController *emplVC = [EmployeeAppeaController loadStroyboard:[EmployeeAppeaController new]];
            emplVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:emplVC animated:YES];
        }
        if ([titleStr isEqualToString:@"诉求研判"]) {
            SqFenFaViewController *emplVC = [SqFenFaViewController loadStroyboard:[SqFenFaViewController new]];
            emplVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:emplVC animated:YES];
        }
        
        
        if ([titleStr isEqualToString:@"诉求办理"]) {
            if ([[TokenManager getSection_normal] isEqualToString:@"1"]) {
                SectionNormalViewController *sqHVC = [SectionNormalViewController loadStroyboard:[SectionNormalViewController new]];
                sqHVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:sqHVC animated:YES];
            }else{
                SqHomeBanliController *sqHVC = [SqHomeBanliController loadStroyboard:[SqHomeBanliController new]];
                sqHVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:sqHVC animated:YES];
                
            }
            
            
            
            
        }
        
        
        
    }
    
    if (indexPath.row == 11) {
        NSString *titleStr = self.titleMuArray[indexPath.row];
        if ([titleStr isEqualToString:@"诉求办理"]) {
            
            if ([[TokenManager getLeader_main]isEqualToString:@"1"]) {
                SqHomeBanliController *sqHVC = [SqHomeBanliController loadStroyboard:[SqHomeBanliController new]];
                sqHVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:sqHVC animated:YES];
            }else{
                SectionNormalViewController *sqHVC = [SectionNormalViewController loadStroyboard:[SectionNormalViewController new]];
                sqHVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:sqHVC animated:YES];
            }
            
            
        }
        
        
    }
    
}

- (IBAction)chuliBtn:(UIButton *)sender {
    self.leftLabel.hidden = NO;
    self.centerLabel.hidden = YES;
    self.rightLabel.hidden = YES;
    [self.handleArray removeAllObjects];
    self.page = 1;
    self.status = @"0";
    [self getListStatus:self.status];
}

- (IBAction)finshBtn:(UIButton *)sender {
    self.leftLabel.hidden = YES;
    self.centerLabel.hidden = NO;
    self.rightLabel.hidden = YES;
    [self.handleArray removeAllObjects];
    self.page = 1;
    self.status = @"1";
    [self getListStatus:self.status];
}
- (IBAction)tuiBtn:(UIButton *)sender {
    self.leftLabel.hidden = YES;
    self.centerLabel.hidden = YES;
    self.rightLabel.hidden = NO;
    [self.handleArray removeAllObjects];
    self.page = 1;
    self.status = @"2";
    [self getListStatus:self.status];
}


-(void)getData{
    WS(weakSelf);
    [[ApiManager ShardInstance] sliderResultBlock:^(NSDictionary *data, NSError *error) {
        BaseModel *model = [BaseModel mj_objectWithKeyValues:data];
        if (model.code == 1) {
            NSArray *array = [BannerModel mj_objectArrayWithKeyValuesArray:data[@"rs"]];
            for (BannerModel *model in array) {
                [weakSelf.bannerArray addObject:[NSString stringWithFormat:@"%@%@",BaseImgUrl,model.image]];
            }
            weakSelf.sdcycleScrollView.imageURLStringsGroup = [weakSelf.bannerArray mutableCopy];
            
        }
    }];
    
}

-(void) getListStatus:(NSString *)status{
    [[ToastManager shardInstance]showSystemProgress:self.view];
    
    WS(weakSelf);
    [[ApiManager ShardInstance]stffListstaff_id:[TokenManager getUserId] page:self.page status:status resultBlock:^(NSDictionary *data, NSError *error) {
        
        [[ToastManager shardInstance]hideProgress:self.view];
        NSArray *array = [AppealModel mj_objectArrayWithKeyValuesArray:data[@"rs"][@"data"]];
        NumberModel *nuModel = [NumberModel mj_objectWithKeyValues:data[@"rs"][@"nums"]];
        
        if ([nuModel.status_0 isEqualToString:@"0"]) {
            weakSelf.leftNumLabel.hidden = YES;
        }else{
            
            weakSelf.leftNumLabel.hidden = NO;
            weakSelf.leftNumLabel.text = nuModel.status_0;
        }
        
        if ([nuModel.status_1 isEqualToString:@"0"]) {
            weakSelf.centerNumLabel.hidden = YES;
        }else{
            
            weakSelf.centerNumLabel.hidden = NO;
            weakSelf.centerNumLabel.text = nuModel.status_1;
        }
        if ([nuModel.status_2 isEqualToString:@"0"]) {
            weakSelf.rightNumLabel.hidden = YES;
        }else{
            
            weakSelf.rightNumLabel.hidden = NO;
            weakSelf.rightNumLabel.text = nuModel.status_2;
        }
        if (array.count ==0) {
            weakSelf.tableView.mj_footer.alpha = 0.0;
        }else{
            weakSelf.tableView.mj_footer.alpha = 1.0;
        }
        
        [self.handleArray addObjectsFromArray:array];
        
        
        
        [self.tableView reloadData];
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
        weakSelf.page ++;
    }];
}
- (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView {
    return YES;
}
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
    return YES;
    
}

- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
    return [UIImage imageNamed: self.handleArray?@"aa":@"pg_internet"];//pg_score1
}

- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
    NSString *text = self.handleArray?@"暂无数据":@"出错啦~，点此重试";
    NSDictionary *attributes = @{NSFontAttributeName: [UIFont boldSystemFontOfSize:15.0f],
                                 NSForegroundColorAttributeName: [UIColor colorWithHexString:@"949494"]};
    return [[NSAttributedString alloc] initWithString:text attributes:attributes];
}

- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
    return 300.00;
}

-(void)getPhone{
    [[ApiManager ShardInstance]getHotTelResultBlock:^(NSDictionary *data, NSError *error) {
        
        [TokenManager saveGetHotTel:[NSString stringWithFormat:@"%@",data[@"rs"]]];
        NSLog(@"%@",[TokenManager getHotTel]);
    }];
}

@end
